package org.hd.taobao.controller;

import org.hd.taobao.entity.User;
import org.hd.taobao.service.IUserService;
import org.hd.taobao.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.io.IOException;

/**
 * @Author: Ben
 * @Date: 2021/4/7 22:29
 */
@WebServlet("/insertUser")
public class InsertUserServlet extends HttpServlet {

    @Override
    public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String userName=req.getParameter("userName");
        String password=req.getParameter("password");
        User user=new User(userName);
        IUserService iUserService=new UserServiceImpl();
        boolean judgment=iUserService.insertUser(user);
        if (judgment){
            req.setAttribute("msg","成功");
        }else {
            req.setAttribute("msg","失败");
        }

        req.getRequestDispatcher("index.jsp").forward(req,resp);
    }
}
